/* 粘性导航 */
const headerEL = document.querySelector("header");
const scrollToTop = document.querySelector(".scrollToTop");
window.addEventListener("scroll", () => {
  let height = headerEL.getBoundingClientRect().height;
  if (window.pageYOffset - height > 800) {
    if (!headerEL.classList.contains("sticky")) {
      headerEL.classList.add("sticky");
    }
  } else {
    headerEL.classList.remove("sticky")
  }
  // 返回顶部
  if (window.pageYOffset > 2000) {
    scrollToTop.style.display = "block"
  } else {
    scrollToTop.style.display = "none"
  }
});

/* 平滑滚动 */
const scroll = new SmoothScroll('nav a[href*="#"],.scrollToTop a[href*="#"]', {
  header: "header",
  offset: 80
});

//关闭全屏导航
document.addEventListener("scrollStart", () => {
  if (headerEL.classList.contains("open")) {
    headerEL.classList.remove("open")
  }
})

//折叠按钮
const burgerEl = document.querySelector(".burger")
burgerEl.addEventListener("click", () => {
  headerEL.classList.toggle("open")
})